﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using Bussiness.Company;
using FOModels.Company;
using FOSystem.CultureHelper;
using Bussiness.Language;
using FOModels.Language;
namespace FO.Controllers
{
    public class CompanyController : CultureController
    {
        //
        // GET: /Company/

        public ActionResult Index()
        {
            return View();
        }
        [Authorize(Roles = "8,9")]
        public ActionResult ShowCase()
        {
            CompanyBLL bll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            List<CompanyModels> list = new List<CompanyModels>();
            list = bll.getCompany(lang.LangID);
            ViewBag.CompanyList = list;
            return View();
        }


        [Authorize(Roles = "8,9")]
        public ActionResult ManagerCompany()
        {
            return View();
        }
        [Authorize(Roles = "8,9")]
        public ActionResult Manager(int CompanyID)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            CompanyBLL combll = new CompanyBLL();
            CompanyModels ca = new CompanyModels();
            ca = combll.getCompanybyID(CompanyID, lang.LangID);
            ViewBag.TableTermInterest = combll.getTableTermInterestbyComID(CompanyID);
            ViewBag.TableTermDemandInterest = combll.getTableTermDemandInterestbyComID(CompanyID);
            ViewBag.TableHomeLoanEquityInterest = combll.getTableHomeLoanEquityInterestbyComID(CompanyID);
            ViewBag.TableHomeLoanMortgageInterest = combll.getTableHomeLoanMortgageInterestbyComID(CompanyID);
            ViewBag.TableCarLoanMortgageInterest = combll.getTableCarLoanMortgageInterestbyComID(CompanyID);
            ViewBag.TableCarLoanEquityInterest = combll.getTableCarLoanEquityInterestbyComID(CompanyID);
            ViewBag.TableCapitalLoanInterest = combll.getTableCapitalLoanInterestbyComID(CompanyID);
            ViewBag.TableFinancialLeasingLoanInterest = combll.getTableFinancialLeasingLoanInterestbyComID(CompanyID);
            ViewBag.TableLongTermLoanInterest = combll.getTableLongTermLoanInterestbyComID(CompanyID);
            ViewBag.TableShortTermLoanInterest = combll.getTableShortTermLoanInterestbyComID(CompanyID);
            ViewBag.TableConsumerLoanInterest = combll.getTableConsumerLoanInterestbyComID(CompanyID);
            ViewBag.TableEducationLoanInterest = combll.getTableEducationLoanInterestbyComID(CompanyID);
            ViewBag.TableOverdraftLoanInterest = combll.getTableOverdraftLoanInterestbyComID(CompanyID);
            ViewBag.TableConsumerInstallmentLoanInterest = combll.getTableConsumerInstallmentLoanInterestbyComID(CompanyID);
            ViewBag.TablePersonalBusinessLoanInterest = combll.getTablePersonalBusinessLoanInterestbyComID(CompanyID);
            ViewBag.TableHomeEquityLoanInterest = combll.getTableHomeEquityLoanInterestbyComID(CompanyID);
            return View(ca);
        }
        public JsonResult getCompanyJson()
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            CompanyBLL bll = new CompanyBLL();
            List<CompanyModels> list = new List<CompanyModels>();
            list = bll.getCompany(lang.LangID);
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        public JsonResult getTermInterestJson(int CompanyID)
        {
            CompanyBLL bll = new CompanyBLL();
            List<TableTermInterestModels> list = bll.getTableTermInterestbyComID(CompanyID);
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableTermInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
           
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableTermInterest(FO.Models.TableTermInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            if (ModelState.IsValid)
            {
                TableTermInterestModels items = new TableTermInterestModels();
                items.Month = term.Month;
                items.InterestVND = term.InterestVND;
                items.InterestEUR = term.InterestEUR;
                items.InterestUSD = term.InterestUSD;
                items.CompanyID = term.CompanyID;
               
                cardbll.InsertTableTermInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);
        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableHomeLoanEquityInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableHomeLoanEquityInterest(FO.Models.TableHomeLoanEquityInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableHomeLoanEquityInterestModels items = new TableHomeLoanEquityInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableHomeLoanEquityInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableCarLoanEquityInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableCarLoanEquityInterest(FO.Models.TableCarLoanEquityInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableCarLoanEquityInterestModels items = new TableCarLoanEquityInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableCarLoanEquityInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableCarLoanMortgageInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableCarLoanMortgageInterest(FO.Models.TableCarLoanMortgageInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableHomeCarMortgageInterestModels items = new TableHomeCarMortgageInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableCarLoanMortgageInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableHomeLoanMortgageInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableHomeLoanMortgageInterest(FO.Models.TableHomeLoanMortgageInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableHomeLoanMortgageInterestModels items = new TableHomeLoanMortgageInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableHomeLoanMortgageInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }


        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableTermDemandInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableTermDemandInterest(FO.Models.TableTermDemandInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableTermDemandInterest items = new TableTermDemandInterest();
                items.Month = term.Month;
                items.InterestVND = term.InterestVND;
                items.InterestEUR = term.InterestEUR;
                items.InterestUSD = term.InterestUSD;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableDemandTermInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertCompany()
        {

            return View();

        }
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertCompany(FO.Models.CompanyInsert card)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                CompanyModels items = new CompanyModels();

                items.Name = card.Name;
                items.Address = card.Address;
                items.CompanyLogo = card.CompanyLogo;
                items.Phone = card.Phone;
                items.Website = card.Website;
                items.Active = false;
                items.ActiveHome = false;
                cardbll.InsertCompany(items);
                ////
                CompanyModels comitem = cardbll.getTOP1Company();
                items.CompanyID = comitem.CompanyID;
                ////

                CompanyModels itemsLang = new CompanyModels();
                itemsLang.CompanyID = comitem.CompanyID;
                itemsLang.Name = card.Name_Lang;
                itemsLang.Address = card.Address_Lang;
                itemsLang.CompanyLogo = card.CompanyLogo;
                itemsLang.Phone = card.Phone;
                itemsLang.Website = card.Website;
                cardbll.InsertCompany(items);
              
                itemsLang.CompanyID = comitem.CompanyID;
                cardbll.InsertCompanyLang(items, 1);
                cardbll.InsertCompanyLang(itemsLang, 2);
                return RedirectToAction("ManagerCompany");
            }
            return View(card);

        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateCompany(int CompanyID)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            CompanyBLL cardbll = new CompanyBLL();
            CompanyModels card = new CompanyModels();
            card = cardbll.getCompanybyID(CompanyID, lang.LangID);
            Models.Company c = new Models.Company();
            c.CompanyID = card.CompanyID;
            c.Name = card.Name;
            c.Address = card.Address;
            c.CompanyLogo = card.CompanyLogo;
            c.Phone = card.Phone;
            c.Website = card.Website;
            c.Active = card.Active;
            c.ActiveHome = card.ActiveHome;
            return View(c);


        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateCompany(FO.Models.Company card)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            CompanyBLL cardbll = new CompanyBLL();
            CompanyModels ca = new CompanyModels();
            ca = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            if (ca != null)
            {
                ca.Name = card.Name;
                ca.Address = card.Address;
                ca.CompanyLogo = card.CompanyLogo;
                ca.Phone = card.Phone;
                ca.Website = card.Website;
                ca.Active = card.Active;
                ca.ActiveHome = card.ActiveHome;
                cardbll.UpdateCompany(ca, lang.LangID);
                return RedirectToAction("ManagerCompany");
            }
            return View();


        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTermInterest(int TableTermInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableTermInterestModels card = cardbll.getTermInterestID(TableTermInterestID);
            Models.TableTermInterest c = new Models.TableTermInterest();
            c.TableTermInterestID = card.TableTermInterestID;
            c.Month = card.Month;
            c.InterestVND = card.InterestVND;
            c.InterestEUR = card.InterestEUR;
            c.InterestUSD = card.InterestUSD;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTermInterest(FO.Models.TableTermInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableTermInterestModels ca = cardbll.getTermInterestID(card.TableTermInterestID);
            if (ca != null)
            {
                ca.Month = card.Month;
                ca.InterestVND = card.InterestVND;
                ca.InterestEUR = card.InterestEUR;
                ca.InterestUSD = card.InterestUSD;
                cardbll.UpdateTableTermInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTermDemandInterest(int TableTermInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableTermDemandInterest card = cardbll.getTermDemandInterestID(TableTermInterestID);
            Models.TableTermDemandInterest c = new Models.TableTermDemandInterest();
            c.Month = card.Month;
            c.InterestVND = card.InterestVND;
            c.InterestEUR = card.InterestEUR;
            c.InterestUSD = card.InterestUSD;
            c.CompanyID = card.CompanyID;
            c.TableTermDemandInterestID = card.TableTermDemandInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTermDemandInterest(FO.Models.TableTermDemandInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableTermDemandInterest ca = cardbll.getTermDemandInterestID(card.TableTermDemandInterestID);
            if (ca != null)
            {
                ca.Month = card.Month;
                ca.InterestVND = card.InterestVND;
                ca.InterestEUR = card.InterestEUR;
                ca.InterestUSD = card.InterestUSD;
                cardbll.UpdateTableTermDemandInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }
        /// <summary>
        /// UpdateTableHomeLoanEquityInterest
        /// </summary>
        /// <param name="CompanyID"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableHomeLoanEquityInterest(int TableHomeLoanEquityInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableHomeLoanEquityInterestModels card = cardbll.getTableHomeLoanEquityInterestID(TableHomeLoanEquityInterestID);
            Models.TableHomeLoanEquityInterest c = new Models.TableHomeLoanEquityInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableHomeLoanEquityInterestID = card.TableHomeLoanEquityInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableHomeLoanEquityInterest(FO.Models.TableHomeLoanEquityInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableHomeLoanEquityInterestModels ca = cardbll.getTableHomeLoanEquityInterestID(card.TableHomeLoanEquityInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableHomeLoanEquityInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableHomeLoanMortgageInterest(int TableHomeLoanMortgageInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableHomeLoanMortgageInterestModels card = cardbll.getTableHomeLoanMortgageInterestID(TableHomeLoanMortgageInterestID);
            Models.TableHomeLoanMortgageInterest c = new Models.TableHomeLoanMortgageInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableHomeLoanMortgageInterestID = card.TableHomeLoanMortgageInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableHomeLoanMortgageInterest(FO.Models.TableHomeLoanMortgageInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableHomeLoanMortgageInterestModels ca = cardbll.getTableHomeLoanMortgageInterestID(card.TableHomeLoanMortgageInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableHomeLoanMortgageInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableCarLoanEquityInterest(int TableCarLoanEquityInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableCarLoanEquityInterestModels card = cardbll.getTableCarLoanEquityInterestID(TableCarLoanEquityInterestID);
            Models.TableCarLoanEquityInterest c = new Models.TableCarLoanEquityInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableCarLoanEquityInterestID = card.TableCarLoanEquityInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableCarLoanEquityInterest(FO.Models.TableCarLoanEquityInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableCarLoanEquityInterestModels ca = cardbll.getTableCarLoanEquityInterestID(card.TableCarLoanEquityInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableCarLoanEquityInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableCarLoanMortgageInterest(int TableCarLoanMortgageInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableHomeCarMortgageInterestModels card = cardbll.getTableCarLoanMortgageInterestID(TableCarLoanMortgageInterestID);
            Models.TableCarLoanMortgageInterest c = new Models.TableCarLoanMortgageInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableCarLoanMortgageInterestID = card.TableCarLoanMortgageInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableCarLoanMortgageInterest(FO.Models.TableCarLoanMortgageInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableHomeCarMortgageInterestModels ca = cardbll.getTableCarLoanMortgageInterestID(card.TableCarLoanMortgageInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableCarLoanMortgageInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteCompany(int CompanyID)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            CompanyBLL bll = new CompanyBLL();
            CompanyModels card = new CompanyModels();
            card = bll.getCompanybyID(CompanyID, lang.LangID);
            if (card != null)
            {
                bll.DeleteCompany(card.CompanyID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTermInterest(int TableTermInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableTermInterestModels card = bll.getTermInterestID(TableTermInterestID);
            if (card != null)
            {
                bll.DeleteTableTermInterest(card.TableTermInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableHomeLoanEquityInterest(int TableHomeLoanEquityInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableHomeLoanEquityInterestModels card = bll.getTableHomeLoanEquityInterestID(TableHomeLoanEquityInterestID);
            if (card != null)
            {
                bll.DeleteTableHomeLoanEquityInterest(card.TableHomeLoanEquityInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableHomeLoanMortgageInterest(int TableHomeLoanMortgageInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableHomeLoanMortgageInterestModels card = bll.getTableHomeLoanMortgageInterestID(TableHomeLoanMortgageInterestID);
            if (card != null)
            {
                bll.DeleteTableHomeLoanMortgageInterest(card.TableHomeLoanMortgageInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTermDemandInterest(int TableTermDemandInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableTermDemandInterest card = bll.getTermDemandInterestID(TableTermDemandInterestID);
            if (card != null)
            {
                bll.DeleteTableTermDemandInterest(card.TableTermDemandInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableCarLoanMortgageInterest(int TableCarLoanMortgageInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableHomeCarMortgageInterestModels card = bll.getTableCarLoanMortgageInterestID(TableCarLoanMortgageInterestID);
            if (card != null)
            {
                bll.DeleteTableCarLoanMortgageInterest(card.TableCarLoanMortgageInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableCarLoanEquityInterest(int TableCarLoanEquityInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableCarLoanEquityInterestModels card = bll.getTableCarLoanEquityInterestID(TableCarLoanEquityInterestID);
            if (card != null)
            {
                bll.DeleteTableCarLoanEquityInterest(card.TableCarLoanEquityInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }


        ///SHORT TERM LOAN
        ///
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableShortTermLoanInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableShortTermLoanInterest(FO.Models.TableShortTermLoanInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableShortTermLoanInterestModels items = new TableShortTermLoanInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableShortTermLoanInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableShortTermLoanInterest(int TableShortTermLoanInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableShortTermLoanInterestModels card = cardbll.getTableShortTermLoanInterestID(TableShortTermLoanInterestID);
            Models.TableShortTermLoanInterest c = new Models.TableShortTermLoanInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableShortTermLoanInterestID = card.TableShortTermLoanInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableShortTermLoanInterest(FO.Models.TableShortTermLoanInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableShortTermLoanInterestModels ca = cardbll.getTableShortTermLoanInterestID(card.TableShortTermLoanInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableShortTermLoanInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableShortTermLoanInterest(int TableShortTermLoanInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableShortTermLoanInterestModels card = bll.getTableShortTermLoanInterestID(TableShortTermLoanInterestID);
            if (card != null)
            {
                bll.DeleteTableShortTermLoanInterest(card.TableShortTermLoanInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }


        ///LONG TERM LOAN
        ///
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableLongTermLoanInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableLongTermLoanInterest(FO.Models.TableLongTermLoanInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableLongTermLoanInterestModels items = new TableLongTermLoanInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableLongTermLoanInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableLongTermLoanInterest(int TableLongTermLoanInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableLongTermLoanInterestModels card = cardbll.getTableLongTermLoanInterestID(TableLongTermLoanInterestID);
            Models.TableLongTermLoanInterest c = new Models.TableLongTermLoanInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableLongTermLoanInterestID = card.TableLongTermLoanInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableLongTermLoanInterest(FO.Models.TableLongTermLoanInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableLongTermLoanInterestModels ca = cardbll.getTableLongTermLoanInterestID(card.TableLongTermLoanInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableLongTermLoanInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableLongTermLoanInterest(int TableLongTermLoanInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableLongTermLoanInterestModels card = bll.getTableLongTermLoanInterestID(TableLongTermLoanInterestID);
            if (card != null)
            {
                bll.DeleteTableLongTermLoanInterest(card.TableLongTermLoanInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }

        ///CAPITAL
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableCapitalLoanInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableCapitalLoanInterest(FO.Models.TableCapitalLoanInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableCapitalLoanInterestModels items = new TableCapitalLoanInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableCapitalLoanInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableCapitalLoanInterest(int TableCapitalLoanInterestID)
        {
            
            CompanyBLL cardbll = new CompanyBLL();
            TableCapitalLoanInterestModels card = cardbll.getTableCapitalLoanInterestID(TableCapitalLoanInterestID);
            Models.TableCapitalLoanInterest c = new Models.TableCapitalLoanInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableCapitalLoanInterestID = card.TableCapitalLoanInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableCapitalLoanInterest(FO.Models.TableCapitalLoanInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableCapitalLoanInterestModels ca = cardbll.getTableCapitalLoanInterestID(card.TableCapitalLoanInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableCapitalLoanInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableCapitalLoanInterest(int TableCapitalLoanInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableCapitalLoanInterestModels card = bll.getTableCapitalLoanInterestID(TableCapitalLoanInterestID);
            if (card != null)
            {
                bll.DeleteTableCapitalLoanInterest(card.TableCapitalLoanInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }
        ///

        ///Financial Leasing Loan
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableFinancialLeasingLoanInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableFinancialLeasingLoanInterest(FO.Models.TableFinancialLeasingLoanInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableFinancialLeasingLoanInterestModels items = new TableFinancialLeasingLoanInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableFinancialLeasingLoanInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableFinancialLeasingLoanInterest(int TableFinancialLeasingLoanInterestID)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            CompanyBLL cardbll = new CompanyBLL();
            TableFinancialLeasingLoanInterestModels card = cardbll.getTableFinancialLeasingLoanInterestID(TableFinancialLeasingLoanInterestID);
            Models.TableFinancialLeasingLoanInterest c = new Models.TableFinancialLeasingLoanInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableFinancialLeasingLoanInterestID = card.TableFinancialLeasingLoanInterestID;
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID,lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableFinancialLeasingLoanInterest(FO.Models.TableFinancialLeasingLoanInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableFinancialLeasingLoanInterestModels ca = cardbll.getTableFinancialLeasingLoanInterestID(card.TableFinancialLeasingLoanInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableFinancialLeasingLoanInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableFinancialLeasingLoanInterest(int TableFinancialLeasingLoanInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableFinancialLeasingLoanInterestModels card = bll.getTableFinancialLeasingLoanInterestID(TableFinancialLeasingLoanInterestID);
            if (card != null)
            {
                bll.DeleteTableFinancialLeasingLoanInterest(card.TableFinancialLeasingLoanInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }
        ///

        //Consumer Loan

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableConsumerLoanInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableConsumerLoanInterest(FO.Models.TableConsumerLoanInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableConsumerLoanInterestModels items = new TableConsumerLoanInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableConsumerLoanInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableConsumerLoanInterest(int TableConsumerLoanInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableConsumerLoanInterestModels card = cardbll.getTableConsumerLoanInterestID(TableConsumerLoanInterestID);
            Models.TableConsumerLoanInterest c = new Models.TableConsumerLoanInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableConsumerLoanInterestID = card.TableConsumerLoanInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableConsumerLoanInterest(FO.Models.TableConsumerLoanInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableConsumerLoanInterestModels ca = cardbll.getTableConsumerLoanInterestID(card.TableConsumerLoanInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableConsumerLoanInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableConsumerLoanInterest(int TableConsumerLoanInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableConsumerLoanInterestModels card = bll.getTableConsumerLoanInterestID(TableConsumerLoanInterestID);
            if (card != null)
            {
                bll.DeleteTableConsumerLoanInterest(card.TableConsumerLoanInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }


        //EducationLoan

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableEducationLoanInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableEducationLoanInterest(FO.Models.TableEducationLoanInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableEducationLoanInterestModels items = new TableEducationLoanInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableEducationLoanInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableEducationLoanInterest(int TableEducationLoanInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableEducationLoanInterestModels card = cardbll.getTableEducationLoanInterestID(TableEducationLoanInterestID);
            Models.TableEducationLoanInterest c = new Models.TableEducationLoanInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableEducationLoanInterestID = card.TableEducationLoanInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableEducationLoanInterest(FO.Models.TableEducationLoanInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableEducationLoanInterestModels ca = cardbll.getTableEducationLoanInterestID(card.TableEducationLoanInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableEducationLoanInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableEducationLoanInterest(int TableEducationLoanInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableEducationLoanInterestModels card = bll.getTableEducationLoanInterestID(TableEducationLoanInterestID);
            if (card != null)
            {
                bll.DeleteTableEducationLoanInterest(card.TableEducationLoanInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }

        //OverdraftLoan

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableOverdraftLoanInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableOverdraftLoanInterest(FO.Models.TableOverdraftLoanInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableOverdraftLoanInterestModels items = new TableOverdraftLoanInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableOverdraftLoanInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableOverdraftLoanInterest(int TableOverdraftLoanInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableOverdraftLoanInterestModels card = cardbll.getTableOverdraftLoanInterestID(TableOverdraftLoanInterestID);
            Models.TableOverdraftLoanInterest c = new Models.TableOverdraftLoanInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableOverdraftLoanInterestID = card.TableOverdraftLoanInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableOverdraftLoanInterest(FO.Models.TableOverdraftLoanInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableOverdraftLoanInterestModels ca = cardbll.getTableOverdraftLoanInterestID(card.TableOverdraftLoanInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableOverdraftLoanInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableOverdraftLoanInterest(int TableOverdraftLoanInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableOverdraftLoanInterestModels card = bll.getTableOverdraftLoanInterestID(TableOverdraftLoanInterestID);
            if (card != null)
            {
                bll.DeleteTableOverdraftLoanInterest(card.TableOverdraftLoanInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }


        //ConsumerInstallmentLoan

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableConsumerInstallmentLoanInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableConsumerInstallmentLoanInterest(FO.Models.TableConsumerInstallmentLoanInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableConsumerInstallmentLoanInterestModels items = new TableConsumerInstallmentLoanInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableConsumerInstallmentLoanInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableConsumerInstallmentLoanInterest(int TableConsumerInstallmentLoanInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableConsumerInstallmentLoanInterestModels card = cardbll.getTableConsumerInstallmentLoanInterestID(TableConsumerInstallmentLoanInterestID);
            Models.TableConsumerInstallmentLoanInterest c = new Models.TableConsumerInstallmentLoanInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableConsumerInstallmentLoanInterestID = card.TableConsumerInstallmentLoanInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableConsumerInstallmentLoanInterest(FO.Models.TableConsumerInstallmentLoanInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableConsumerInstallmentLoanInterestModels ca = cardbll.getTableConsumerInstallmentLoanInterestID(card.TableConsumerInstallmentLoanInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableConsumerInstallmentLoanInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableConsumerInstallmentLoanInterest(int TableConsumerInstallmentLoanInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableConsumerInstallmentLoanInterestModels card = bll.getTableConsumerInstallmentLoanInterestID(TableConsumerInstallmentLoanInterestID);
            if (card != null)
            {
                bll.DeleteTableConsumerInstallmentLoanInterest(card.TableConsumerInstallmentLoanInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }


        //PersonalBusinessLoan

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTablePersonalBusinessLoanInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTablePersonalBusinessLoanInterest(FO.Models.TablePersonalBusinessLoanInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TablePersonalBusinessLoanInterestModels items = new TablePersonalBusinessLoanInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTablePersonalBusinessLoanInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTablePersonalBusinessLoanInterest(int TablePersonalBusinessLoanInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TablePersonalBusinessLoanInterestModels card = cardbll.getTablePersonalBusinessLoanInterestID(TablePersonalBusinessLoanInterestID);
            Models.TablePersonalBusinessLoanInterest c = new Models.TablePersonalBusinessLoanInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TablePersonalBusinessLoanInterestID = card.TablePersonalBusinessLoanInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTablePersonalBusinessLoanInterest(FO.Models.TablePersonalBusinessLoanInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TablePersonalBusinessLoanInterestModels ca = cardbll.getTablePersonalBusinessLoanInterestID(card.TablePersonalBusinessLoanInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTablePersonalBusinessLoanInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTablePersonalBusinessLoanInterest(int TablePersonalBusinessLoanInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TablePersonalBusinessLoanInterestModels card = bll.getTablePersonalBusinessLoanInterestID(TablePersonalBusinessLoanInterestID);
            if (card != null)
            {
                bll.DeleteTablePersonalBusinessLoanInterest(card.TablePersonalBusinessLoanInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }


        //HomeEquityLoan

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableHomeEquityLoanInterest(int CompanyID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(CompanyID, lang.LangID);
            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertTableHomeEquityLoanInterest(FO.Models.TableHomeEquityLoanInterest term)
        {
            CompanyBLL cardbll = new CompanyBLL();
            if (ModelState.IsValid)
            {
                TableHomeEquityLoanInterestModels items = new TableHomeEquityLoanInterestModels();
                items.Years = term.Years;
                items.InterestVND = term.InterestVND;
                items.CompanyID = term.CompanyID;
                cardbll.InsertTableHomeEquityLoanInterest(items);
                return RedirectToAction("/Manager/" + term.CompanyID + "");
            }
            return View(term);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableHomeEquityLoanInterest(int TableHomeEquityLoanInterestID)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableHomeEquityLoanInterestModels card = cardbll.getTableHomeEquityLoanInterestID(TableHomeEquityLoanInterestID);
            Models.TableHomeEquityLoanInterest c = new Models.TableHomeEquityLoanInterest();
            c.Years = card.Years;
            c.InterestVND = card.InterestVND;
            c.CompanyID = card.CompanyID;
            c.TableHomeEquityLoanInterestID = card.TableHomeEquityLoanInterestID;
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.Company = cardbll.getCompanybyID(card.CompanyID, lang.LangID);
            return View(c);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateTableHomeEquityLoanInterest(FO.Models.TableHomeEquityLoanInterest card)
        {
            CompanyBLL cardbll = new CompanyBLL();
            TableHomeEquityLoanInterestModels ca = cardbll.getTableHomeEquityLoanInterestID(card.TableHomeEquityLoanInterestID);
            if (ca != null)
            {
                ca.Years = card.Years;
                ca.InterestVND = card.InterestVND;
                cardbll.UpdateTableHomeEquityLoanInterest(ca);
                return RedirectToAction("/Manager/" + ca.CompanyID + "");
            }
            return View();


        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteTableHomeEquityLoanInterest(int TableHomeEquityLoanInterestID)
        {
            CompanyBLL bll = new CompanyBLL();
            TableHomeEquityLoanInterestModels card = bll.getTableHomeEquityLoanInterestID(TableHomeEquityLoanInterestID);
            if (card != null)
            {
                bll.DeleteTableHomeEquityLoanInterest(card.TableHomeEquityLoanInterestID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }

    }
}
